package org.example.vueadminapi2.dto;

public class Result {
/**封装响应结果
 * @FileName: Result
 * @Description:
 * @Author: cyx
 * @date: 2025-02-24
 **/
    private int code=0;
    private String msg="ok";
    private Object data;

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
    public static Result ok(){
        Result result=new Result();
        result.setCode(0);
        result.setMsg("ok");
        return result;
    }
    public static Result ok(Object data){
        Result result=new Result();
        result.setCode(0);
        result.setMsg("ok");
        result.setData(data);
        return result;
    }

    public static Result error(Object data){
        Result result=new Result();
        result.setCode(1);
        result.setMsg("error");
        result.setData(data);
        return result;
    }
    public static Result error(String msg){
        Result result=new Result();
        result.setCode(1);
        result.setMsg(msg);
        return result;
    }

    public Result() {
    }

    public Result(Object data) {
        this.data = data;
    }

    public Result(int code) {
        this.code = code;
    }

    public Result(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
}
